//
//  LDMusicViewModel.m
//  MVVM
//
//  Created by 宜必鑫科技 on 2017/10/19.
//  Copyright © 2017年 宜必鑫科技. All rights reserved.
//

#import "LDMusicViewModel.h"
#import "MusicNetTool.h"

@implementation LDMusicViewModel



//获取数据
- (void)getDataFromNetCompleteHandle:(CompletionHandle)completionHandle
{
    [MusicNetTool getMusicDataWithPageId:self.pageIndex completionHandle:^(id resuposeObject, NSError *error) {
        if (!error) {
            NSArray *array = resuposeObject[@"data"][@"list"];
            if(self.pageIndex == 1)
            {
                [self.dataArr removeAllObjects];
                for (NSDictionary *dic in array) {
                    LDPlayMusicModel *model = [LDPlayMusicModel mj_objectWithKeyValues:dic];
                    [self.dataArr addObject:model];
                }
            }
            else if(self.pageIndex > 1)
            {
                for (NSDictionary *dic in array)
                {
                    LDPlayMusicModel *model = [LDPlayMusicModel mj_objectWithKeyValues:dic];
                    [self.dataArr addObject:model];
                }
            }
        }
        WJLogError(@"addObject 刷新 %ld",self.pageIndex );

        completionHandle(error);
    }];
}

//获取更多
- (void)getMoreDataCompletionHandle:(CompletionHandle)completionHandle
{
    self.pageIndex++;
    [self getDataFromNetCompleteHandle:completionHandle];
}
//刷新
- (void)refreshDataCompletionHandle:(CompletionHandle)completionHandle
{
    self.pageIndex = 1;
    [self getDataFromNetCompleteHandle:completionHandle];
}


@end
